Imports Microsoft.VisualBasic
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports SubSonic
Imports ClubStarterKit.Data

Namespace ClubStarterKit.Web
    Public Class CMS

        Public Shared Function GetContent(ByVal sectionname As String) As String
            Dim str As String = ""
            Dim qry As New Query(Tables.WebContent)
            qry.AddWhere(WebContent.Columns.Section, sectionname)
            If qry.GetRecordCount() = 1 Then
                Dim Content As New WebContent(WebContent.Columns.Section, LCase(sectionname))

                If Content.IsLoaded Then
                    str = Content.SectionContent.ToString()
                End If
            Else
                str = "IsNotAdded"
            End If
            Return str
        End Function

        Public Shared Sub UpdateContent(ByVal sectionname As String, ByVal content As String)
            Dim qry As New Query(Tables.WebContent)
            qry.AddWhere(WebContent.Columns.Section, sectionname)
            qry.QueryType = QueryType.Update
            qry.AddUpdateSetting(WebContent.Columns.SectionContent, content)
            qry.AddUpdateSetting(WebContent.Columns.DteTime, DateTime.Now())
            qry.Execute()
        End Sub

        Public Shared Sub AddContent(ByVal sectionname As String, ByVal content As String)
            WebContent.Insert(sectionname, content, DateTime.Now())
        End Sub

        Public Shared Sub ReportUpdate(ByVal OrigionalContent As String, ByVal NewContent As String, ByVal sectionname As String, ByVal IPAddress As String)
            Dim mail As New System.Net.Mail.MailMessage

            mail.To.Add(ClubStarterKit.Web.Settings.Webmaster())
            mail.Subject = ClubStarterKit.Web.Settings.Name() & " - " & sectionname & " Content Update"

            mail.Body += "Date: " & DateTime.Now.ToShortDateString() & " " & DateTime.Now.ToShortTimeString()
            mail.Body += "<br />"
            mail.Body += "Section: " & sectionname
            mail.Body += "<br />"
            mail.Body += "IP Address: " & IPAddress
            mail.Body += "<br />"
            mail.Body += "Origional Content: " & OrigionalContent
            mail.Body += "<br />"
            mail.Body += "New Content: " & NewContent

            mail.IsBodyHtml = True

            Dim smtp As New System.Net.Mail.SmtpClient
            smtp.Send(mail)
        End Sub

    End Class
End Namespace